| Conditions | 1 |
| Paths | 1 |
| Total Lines | 64 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | 'use babel'; |
||
| 10 | describe('DevmindBeautifier', () => { |
||
| 11 | let workspaceElement, activationPromise; |
||
| 12 | |||
| 13 | beforeEach(() => { |
||
| 14 | workspaceElement = atom.views.getView(atom.workspace); |
||
|
|
|||
| 15 | activationPromise = atom.packages.activatePackage('devmind-beautifier'); |
||
| 16 | }); |
||
| 17 | |||
| 18 | describe('when the devmind-beautifier:toggle event is triggered', () => { |
||
| 19 | it('hides and shows the modal panel', () => { |
||
| 20 | // Before the activation event the view is not on the DOM, and no panel |
||
| 21 | // has been created |
||
| 22 | expect(workspaceElement.querySelector('.devmind-beautifier')).not.toExist(); |
||
| 23 | |||
| 24 | // This is an activation event, triggering it will cause the package to be |
||
| 25 | // activated. |
||
| 26 | atom.commands.dispatch(workspaceElement, 'devmind-beautifier:toggle'); |
||
| 27 | |||
| 28 | waitsForPromise(() => { |
||
| 29 | return activationPromise; |
||
| 30 | }); |
||
| 31 | |||
| 32 | runs(() => { |
||
| 33 | expect(workspaceElement.querySelector('.devmind-beautifier')).toExist(); |
||
| 34 | |||
| 35 | let devmindBeautifierElement = workspaceElement.querySelector('.devmind-beautifier'); |
||
| 36 | expect(devmindBeautifierElement).toExist(); |
||
| 37 | |||
| 38 | let devmindBeautifierPanel = atom.workspace.panelForItem(devmindBeautifierElement); |
||
| 39 | expect(devmindBeautifierPanel.isVisible()).toBe(true); |
||
| 40 | atom.commands.dispatch(workspaceElement, 'devmind-beautifier:toggle'); |
||
| 41 | expect(devmindBeautifierPanel.isVisible()).toBe(false); |
||
| 42 | }); |
||
| 43 | }); |
||
| 44 | |||
| 45 | it('hides and shows the view', () => { |
||
| 46 | // This test shows you an integration test testing at the view level. |
||
| 47 | |||
| 48 | // Attaching the workspaceElement to the DOM is required to allow the |
||
| 49 | // `toBeVisible()` matchers to work. Anything testing visibility or focus |
||
| 50 | // requires that the workspaceElement is on the DOM. Tests that attach the |
||
| 51 | // workspaceElement to the DOM are generally slower than those off DOM. |
||
| 52 | jasmine.attachToDOM(workspaceElement); |
||
| 53 | |||
| 54 | expect(workspaceElement.querySelector('.devmind-beautifier')).not.toExist(); |
||
| 55 | |||
| 56 | // This is an activation event, triggering it causes the package to be |
||
| 57 | // activated. |
||
| 58 | atom.commands.dispatch(workspaceElement, 'devmind-beautifier:toggle'); |
||
| 59 | |||
| 60 | waitsForPromise(() => { |
||
| 61 | return activationPromise; |
||
| 62 | }); |
||
| 63 | |||
| 64 | runs(() => { |
||
| 65 | // Now we can test for view visibility |
||
| 66 | let devmindBeautifierElement = workspaceElement.querySelector('.devmind-beautifier'); |
||
| 67 | expect(devmindBeautifierElement).toBeVisible(); |
||
| 68 | atom.commands.dispatch(workspaceElement, 'devmind-beautifier:toggle'); |
||
| 69 | expect(devmindBeautifierElement).not.toBeVisible(); |
||
| 70 | }); |
||
| 71 | }); |
||
| 72 | }); |
||
| 73 | }); |
||
| 74 |
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.